package com.example.fw;

import java.util.Random;

public class RandomizeHelper extends WebDriverHelperBase
{
	private static final String[] symbols = { "~", "!", "@", "#", "$", "%", "^", "&", "(", ")", "_", "{", "}", "[", "]", "/", "|", "?", ".", ":", ";", "*" };
	private static final String[] forbiddenSymbols = { "\\", "\'", "\"", " ", "," };
	private static final String[] letters = { "", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
			"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
			"Z" };
	private static final String[] month = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
			"December" };

	public RandomizeHelper(ApplicationManager manager)
	{
		super(manager);
	}

	public static Integer getRandomNumber(int minValue, int maxValue)
	{
		Random random = new Random();
		int randomNumber = 0;

		randomNumber = random.nextInt((maxValue + 1) - minValue) + (minValue);

		if (randomNumber == 0)
		{
			randomNumber += 1;
		}

		return randomNumber;
	}

	public static String getRandomSymbol()
	{
		int randomSymbolIndex = getRandomNumber(1, symbols.length - 1);

		while (symbols[randomSymbolIndex].equals("-") || symbols[randomSymbolIndex].equals("_"))
		{
			randomSymbolIndex = getRandomNumber(1, symbols.length - 1);
		}

		return symbols[randomSymbolIndex];
	}

	public static String getRandomLetter()
	{
		int randomLetterIndex = getRandomNumber(1, letters.length - 1);

		return letters[randomLetterIndex];
	}

	public static String getRandomLetters(Integer stringLenght)
	{
		String string = "";

		for (int i = 0; i < stringLenght; i++)
		{
			string += getRandomLetter();
		}

		return string;
	}

	public static Integer getRandomNumbers(Integer numberLenght)
	{
		Integer number = 0;

		for (int i = 0; i < numberLenght; i++)
		{
			number = number * 10 + getRandomNumber(0, 9);
		}

		return number;
	}

	public static String getRandomSimbols(Integer stringLenght)
	{
		String symbols = "";

		for (int i = 0; i < stringLenght; i++)
		{
			symbols += getRandomSymbol();
		}

		return symbols;
	}

	public static String generateRandomSuffix(String core)
	{
		String string = "";
		int rnd = getRandomNumber(0, 5);
		if (rnd == 0 || rnd == 1)
		{
			string = "";
		}
		else if (rnd == -1)
		{
			string = getRandomSymbol();
		}
		else
		{
			string = core + getRandomLetters(getRandomNumber(0, 5)) + getRandomNumber(0, 100);
		}

		return string;
	}

	public static String getRandomMonth()
	{
		int randomMonthNumber = getRandomNumber(1, month.length - 1);

		return month[randomMonthNumber];
	}
}